package com.xiangyang.pos.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xiangyang.pos.R;
import com.xiangyang.pos.bean.UserShoppingDataBean;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by Administrator on 2017/8/18 0018.
 *
 * 用户购买记录适配器
 *
 * @author YeDalin
 *
 */

public class UserShoppingDataRecyclerViewAdapter extends RecyclerView.Adapter<UserShoppingDataRecyclerViewAdapter.ViewHolder> {

    private List<UserShoppingDataBean.UserShop> list;

    public UserShoppingDataRecyclerViewAdapter(List<UserShoppingDataBean.UserShop> list) {
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_shopping_data_recycler_view, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        if (list.size() != 0) {
            holder.tvProductName.setText(list.get(position).getTitle());
            holder.tvProductNumber.setText(list.get(position).getNum() + "");
            holder.tvProductPrice.setText("￥" + list.get(position).getPrice());

            DecimalFormat df = new DecimalFormat("######0.00");
            double d=list.get(position).getNum() * list.get(position).getPrice();


            holder.tvMoney.setText("￥" + df.format(d));
        }

    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tvProductName;
        public TextView tvProductNumber;
        public TextView tvProductPrice;
        public TextView tvMoney;

        public ViewHolder(View itemView) {
            super(itemView);
            tvProductName = itemView.findViewById(R.id.tv_product_name);
            tvProductPrice = itemView.findViewById(R.id.tv_product_price);
            tvProductNumber = itemView.findViewById(R.id.tv_product_number);
            tvMoney = itemView.findViewById(R.id.tv_money);
        }
    }

}
